<?php

/**
 * @author ducnhat
 * @email ddnhat@gmail.com
 * @copyright 2014
 */
 
class Admin_SettingController extends Zenddn_Controller_Action{
	
	public function init(){
		parent::init();
        parent::loadTemplate('alpona');
        $this->view->headTitle = "setting";
	}
	
	public function indexAction(){
	    $request = $this->_request;
        
        $setting_model = new Admin_Model_Setting();
        $settings = $setting_model->getSetting('general');
        
        if($settings){
            $this->view->data = unserialize($settings);
        }
        
		if($request->isPost()){
            $params = $request->getParams();
            
            unset($params['module']);
            unset($params['controller']);
            unset($params['action']);
            
            $setting_model->saveSetting('general', serialize($params));
            
            $this->_helper->_redirector->gotoRoute(array('module' => 'admin', 'controller' => 'setting', 'action' => 'index'), null, true);
        }
	}
    
    public function pageAction(){
        parent::addStyleSheet(array('jquery-select.css'));
        parent::addScripts(array('jquery-select.js'));
        
    	$post_model = new Admin_Model_Post();
        $posts = $post_model->getDatas(array('where' => 'status = 1', 'order' => 'created DESC'), array('id', 'title'));
        
        $category_model = new Admin_Model_PostCategory();
        $categories = $category_model->getDatas(array('where' => 'status = 1'), array('id', 'category'));
        
        $setting_model = new Admin_Model_Setting();
        $settings = $setting_model->getSetting('page');
        
        if($settings){
            $this->view->data = unserialize($settings);
        }
        
        $this->view->categories = $categories;
        $this->view->posts = $posts;
        
        $request = $this->_request;
        
        if($request->isPost()){
            $params = $request->getParams();
            
            unset($params['module']);
            unset($params['controller']);
            unset($params['action']);
            
            $setting_model->saveSetting('page', serialize($params));
            
            $this->_helper->_redirector->gotoRoute(array('module' => 'admin', 'controller' => 'setting', 'action' => 'page'), null, true);
        }
    }
    
    public function bannerAction(){
        
    }
    
    public function deleteAction(){
        
    }
}